package com.gnerv.cms.controller;


import com.gnerv.cms.entity.Catalog;
import com.gnerv.cms.entity.R;
import com.gnerv.cms.service.ICatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * CMS平台-栏目表 前端控制器
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-07-01
 */
@RestController
@RequestMapping("/cms/catalog")
public class CatalogController {

    @Autowired
    ICatalogService catalogService;

    @RequestMapping(value = "create", method = RequestMethod.POST)
    public R createCatalog(@RequestBody Catalog catalog) {
        catalogService.createCatalog(catalog);
        return R.back();
    }

    @RequestMapping(value = "delete/{bId}", method = RequestMethod.GET)
    public R deleteCatalog(@PathVariable("bId") String bId) {
        catalogService.deleteCatalog(bId);
        return R.back();
    }

    @RequestMapping(value = "update", method = RequestMethod.POST)
    public R updateCatalog(@RequestBody Catalog catalog) {
        catalogService.updateCatalog(catalog);
        return R.back();
    }

    @RequestMapping(value = "select/{bId}", method = RequestMethod.GET)
    public R selectCatalog(@PathVariable String bId) {
        Catalog catalog = catalogService.selectCatalog(bId);
        return R.back().data("catalog", catalog);
    }

    @RequestMapping(value = "select/tree/{bId}", method = RequestMethod.GET)
    public R selectCatalogTree(@PathVariable String bId) {
        List<Catalog> catalogs = catalogService.selectCatalogTree(bId);
        return R.back().data("catalogs", catalogs);
    }

    @RequestMapping(value = "list", method = RequestMethod.POST)
    public R listCatalog(@RequestBody Catalog catalog) {
        List<Catalog> catalogs = catalogService.listCatalog(catalog);
        return R.back().data("catalogs", catalogs);
    }

}
